(function(window) {
	var vm;

	function mounted() {
		vm = this;
		$.plusReady(function() {
			var gallery = mui('.mui-slider');
			gallery.slider({
				interval: 5000 //自动轮播周期，若为0则不自动播放，默认为0；
			});
			$.loadLib('echarts', function() {
				vm.deviceEchartsOpts.seriesData = [{
					value: '8',
					name: '在线'
				}, {
					value: '2',
					name: '离线'
				}];
				vm.apEchartsOpts.seriesData = [{
					value: '93',
					name: '在线'
				}, {
					value: '7',
					name: '离线'
				}];
				vm.staEchartsOpts.xAxisData = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
				vm.staEchartsOpts.seriesData = [820, 932, 901, 934, 1290, 1330, 1320];
			});
			getRegions();
		});

	}

	function getRegions() {
		var regions = JSON.parse(window.localStorage.getItem('regions'));
		if(!regions) {
			v3Restshop.getRegion('longguanshiyanju', function(code, data) {
				if(data.length) {
					window.localStorage.setItem('regions', JSON.stringify(data));
					$.each(data, function(index, item) {
						if(!item.parentId) {
							vm.branch = item;
						}
					});
					if(!vm.branch) {
						vm.branch = data[0];
					}
					vm.branch.type = 'region';
					window.localStorage.setItem('branch', JSON.stringify(vm.branch));
				}
			});
		} else {
			vm.branch = JSON.parse(window.localStorage.getItem('branch'));
			if(!vm.branch) {
				$.each(regions, function(index, item) {
					if(!item.parentId) {
						vm.branch = item;

					}
				});
				if(!vm.branch) {
					vm.branch = data[0];
				}
				vm.branch.type = 'region';
				window.localStorage.setItem('branch', JSON.stringify(vm.branch));
			}
		}
	}
	window.home = {
		data: {
			branch: '',
			deviceEchartsOpts: {
				seriesData: []
			},
			apEchartsOpts: {
				seriesData: []
			},
			staEchartsOpts: {
				xAxisData: [],
				seriesData: []
			}
		},
		computed: {
			deviceEcharts: echartFactory.createPieChartOption("deviceEchartsOpts"),
			apEcharts: echartFactory.createPieChartOption("apEchartsOpts"),
			staEcharts: echartFactory.createLineChartOption("staEchartsOpts")
		},

		mounted: mounted
	}

})(window);